import { NNumberAnimation } from "naive-ui";
import type { NumberAnimationProps, NumberAnimationInst } from "naive-ui";
import type { HTMLAttributes } from "vue";
export type NumberAnimationFactoryConstructorType = {
  props?: NumberAnimationProps;
  attrs?: HTMLAttributes;
};
export class NumberAnimationFactory {
  private props: NumberAnimationProps = {};
  private attrs: HTMLAttributes = {};
  private domRef: NumberAnimationInst | null = null;

  constructor(data?: NumberAnimationFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
  }

  setProps(props: NumberAnimationProps) {
    this.props = props;
    return this;
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }

  play() {
    this.domRef?.play();
  }

  create() {
    return (
      <NNumberAnimation
        ref={(el: HTMLElement) => {
          this.domRef = el as unknown as NumberAnimationInst;
        }}
        {...this.props}
        {...this.attrs}
      ></NNumberAnimation>
    );
  }
}
